-
-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: adding globalAwait option #102
Conversation
Congratulations 🎉. DeepCode analyzed your code in 5.62 seconds and we found no issues. Enjoy a moment of no bugs ☀️. 👉 View analysis in DeepCode’s Dashboard | Configure the bot |
Sorry for taking so long, I will take a look at this today. |
src/compile-string.ts
Outdated
@@ -26,6 +26,7 @@ export default function compileToString(str: string, config: EtaConfig): string | |||
(config.include ? ',include=E.include.bind(E)' : '') + | |||
(config.includeFile ? ',includeFile=E.includeFile.bind(E)' : '') + | |||
'\nfunction layout(p,d){__l=p;__lP=d}\n' + | |||
(config.globalAwait ? 'let prs = [];\n' : '') + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we could rename this to _prs
? That is something I have seen many tools which need to add additional variables use so it doesn't conflict with the actual code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you format this with prettier/eslint?
This option adds all data objects into an array and await for it globally.
@shadowtime2000 This should be good ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still trying to figure out how exactly this would be tested, but if you know a way could you test this?
Hey @shadowtime2000, sorry for the late response. |
@SilentVoid13 Sorry for the late response. Sorry, I am a little scared of merging something like this which is kind of hard to test so I am going to put this on hold I guess. Sorry again. |
I'm going to close this as stale and because it's for Eta v2. I'd be open to accepting a pull request with this functionality for v3. |
Implements feature of #99.
This feature allows us to add all data objects in an array and to await for it globally (only when the
globalAwait
option is set to true in the config).This adds almost no overhead at runtime (adding a for loop to generate the array push, but that's neglectable overhead), because
Promise.all
just returns the value of synchronous functions and variables and only awaits for asynchronous functions. This could even be the default behavior when resolving templates (removing the option).This allows us to speed things up a lot when having a lot of asynchronous functions in our data object.
Because this doesn't change anything about how this template engine works and just adds some extra speed, I don't think this is an out of scope feature, it is very useful when dealing with asynchronous functions.